﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Domain.Enum;
using IntelligentAgriculture.WebAPI.Application.Command.SheepRescissionCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using NPOI.XSSF.UserModel;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 羊只转舍控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepRescissionController : ControllerBase
    {
        private readonly IMediator _mediator;
        public SheepRescissionController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 转舍类型枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object GetDepartMent()
        {
            List<object> list = new List<object>();
            foreach (var item in Enum.GetValues<RescissionType>())
            {
                list.Add(new
                {
                    name = item.ToString(),
                    value = item
                });
            }
            return Results<object>.DataResult(list);
        }
        /// <summary>
        /// 获取羊只转舍列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<PageOutput<SheepRescissionOutput>>> GetSheepRescissions([FromBody] SheepRescissionInput input)
        {
            var command = new GetSheepRescissionCommand(input);
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取羊只转舍耳号
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<List<Eartag>>> GetSheepRescissionEarTag()
        {
            var command = new SheepRescissionEarTagCommand();
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 新增羊只转舍
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddSheepRescission([FromBody] List<Sheeprescission> input)
        {
            var command = new AddSheepRescissionCommand(input);
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除羊只转舍
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<Results<int>> DeleteSheepRescission(DelSheepRescissionCommand input)
        {
            var command = new DelSheepRescissionCommand(input.userId, input.ids);
            return await _mediator.Send(command);
        }
    }
}
